/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package org.datedemo;

import java.util.Calendar;
import java.util.Date;

/**
 * <p>Project: jse2302 - Date3
 * <p>Powered by webrx On 2023-06-16 16:15:10
 * <p>Created by IntelliJ IDEA
 *
 * @author  webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Date3 {
    public static void main(String[] args) {
        Date d = new Date();
        System.out.printf("%tF %<tT%n", d);

        Date d2 = new Date(Long.MAX_VALUE);
        //9999-12-31 23:59:59
        System.out.printf("%tF %<tT%n", d2);

        Calendar c = Calendar.getInstance();
        c.set(-100, Calendar.DECEMBER, 31, 23, 59, 59);
        System.out.printf("%tF %<tT%n", c);
        System.out.println(c.getTimeInMillis());
        Date d3 = c.getTime();
        System.out.println(d3.getTime());

        //c.get()
        //c.set()
        //c.add()

        System.out.println("--------------------");
        System.out.printf("%tF %<tT%n", -1000 * 60 * 60 * 100L);

        //5天前
        Calendar c2 = Calendar.getInstance();
        c2.add(Calendar.DATE, -5);
        System.out.println();
        System.out.printf("%tF %<tT%n", c2);

        c2.add(Calendar.HOUR_OF_DAY, 72);
        System.out.println();
        System.out.printf("%tF %<tT%n", c2);

        //计算两个日期之间有多长 天
        Calendar c3 = Calendar.getInstance();
        c3.set(1985, 12 - 1, 15, 8, 8, 8);
        Calendar c4 = Calendar.getInstance();
        //c4.set(2000, 1 - 1, 15, 8, 8, 8);

        long ss = c3.getTimeInMillis();
        long ee = c4.getTimeInMillis();
        long ms = ee - ss;
        long days = (ee - ss) / (1000 * 60 * 60 * 24);
        System.out.printf("日期：%tF %<tT到日期：%tF %<tT，共有%d天%n", c3, c4, days);


    }
}
